package com.xls.rong.Utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;
import com.xls.rong.entity.User;

/**
 * Created by Administrator on 2017/7/14.
 */

public class PreferenceUtil {
    private static final String PREFERENCE_USER = "user";

    public static User getUser(Context context){
        SharedPreferences sp = context.getSharedPreferences(PREFERENCE_USER,Context.MODE_PRIVATE);
        String json = sp.getString("user","");
        Gson gson = new Gson();
        User user = gson.fromJson(json,User.class);
        return user;
    }

    public static void saveUser(Context context,User user){
        SharedPreferences sp = context.getSharedPreferences(PREFERENCE_USER,Context.MODE_PRIVATE);
        Gson gson = new Gson();
        String json = gson.toJson(user);
        sp.edit().putString("user",json).apply();
    }
}
